﻿@using Microsoft.JSInterop
@using Covenant.Models.Indicators
@using Covenant.Components.Shared
@inject IJSRuntime IJSRuntime

<CovenantTable TItem="TargetIndicator" Items="TargetIndicators.ToList()" SearchRow="IsRowDisplayed"
               IsSearchable="IsSearchable" IsSortable="IsSortable" IsPaginated="IsPaginated" PageLength="PageLength" class="table table-hover">
    <TableHeader>
        <SortableTableHeader TItem="TargetIndicator" TItem2="string" GetSortableProperty="(indicator) => indicator.ComputerName">
            <HeaderContent>ComputerName</HeaderContent>
        </SortableTableHeader>
        <SortableTableHeader TItem="TargetIndicator" TItem2="string" GetSortableProperty="(indicator) => indicator.UserName">
            <HeaderContent>UserName</HeaderContent>
        </SortableTableHeader>
    </TableHeader>
    <TableRow Context="indicator">
        <tr>
            <td>@indicator.ComputerName</td>
            <td>@indicator.UserName</td>
        </tr>
    </TableRow>
</CovenantTable>

@code {
    [Parameter]
    public IEnumerable<TargetIndicator> TargetIndicators { get; set; }

    [Parameter]
    public bool IsSearchable { get; set; } = false;

    [Parameter]
    public bool IsSortable { get; set; } = true;

    [Parameter]
    public bool IsPaginated { get; set; } = true;

    [Parameter]
    public int PageLength { get; set; } = 25;

    private bool IsRowDisplayed(TargetIndicator indicator, string SearchTerm)
    {
        return SearchTerm == string.Empty ||
            indicator.ComputerName.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
            indicator.UserName.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase);
    }
}
